package org.jeecg.modules.mobile.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.basic.material.entity.BasicMaterial;
import org.jeecg.modules.basic.material.service.IBasicMaterialService;
import org.jeecg.modules.basic.materialtype.entity.BasicMaterialType;
import org.jeecg.modules.basic.materialtype.service.IBasicMaterialTypeService;
import org.jeecg.modules.business.takestockplan.entity.TakeStockPlanExecuteMaterial;
import org.jeecg.modules.business.takestockplan.entity.VO.TakeStockPlanExecuteMaterialVO;
import org.jeecg.modules.flow.sys.entity.dto.BaseFlowDto;
import org.jeecg.modules.mobile.entity.vo.MobileTakeStockPlanCreateVO;
import org.jeecg.modules.mobile.entity.vo.MobileTakeStockPlanParamVO;
import org.jeecg.modules.mobile.service.IMobileTakeStockPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* @Description: 移动端-盘点
* @Author: jeecg-boot
* @Date:   2023-10-09
* @Version: V1.0
*/
@Api(tags="移动端-盘点")
@RestController
@RequestMapping("/mobile/takeStockPlan")
@Slf4j
public class MobileTakeStockPlanController {

    @Autowired
    private IBasicMaterialTypeService basicMaterialTypeService;
    @Autowired
    private IBasicMaterialService basicMaterialService;
    @Autowired
    private IMobileTakeStockPlanService mobileTakeStockPlanService;

    /**
     * 查询物料分类
     */
    @ApiOperation(value = "查询物料分类", notes = "查询物料分类")
    @GetMapping("/queryMaterialType")
    public Result<List<BasicMaterialType>> queryMaterialType(@ApiParam("名称") String name) {
        List<BasicMaterialType> list = basicMaterialTypeService.list(new LambdaQueryWrapper<BasicMaterialType>()
                .like(StringUtils.isNotBlank(name), BasicMaterialType::getName, name));
        return Result.OK(list);
    }

    /**
     * 查询物料编码
     */
    @ApiOperation(value = "查询物料编码", notes = "查询物料编码")
    @GetMapping("/queryMaterial")
    public Result<List<BasicMaterial>> queryMaterial(@ApiParam("物料编码") String name) {
        List<BasicMaterial> list = basicMaterialService.list(new LambdaQueryWrapper<BasicMaterial>()
                .like(StringUtils.isNotBlank(name), BasicMaterial::getCode, name));
        return Result.OK(list);
    }

    /**
     * 根据盘点范围类型查询
     */
    @ApiOperation(value = "根据盘点范围类型查询", notes = "根据盘点范围类型查询")
    @GetMapping("/queryByType")
    public Result<List<MobileTakeStockPlanCreateVO>> queryByType(@ApiParam("盘点范围类型,1 指定仓库,2 指定库区,3 指定物料分类,4 指定物料,5 指定生产订单,6 指定客商") String type) {
        return Result.OK(mobileTakeStockPlanService.queryByType(type));
    }

    /**
     * 盘点第二次扫码查询物料编码，批次号
     */
    @ApiOperation(value = "盘点第二次扫码查询物料编码，批次号", notes = "盘点第二次扫码查询物料编码，批次号")
    @GetMapping("/queryScan")
    public Result<List<TakeStockPlanExecuteMaterial>> queryScan(MobileTakeStockPlanParamVO param) {
        return Result.OK(mobileTakeStockPlanService.queryScan(param));
    }

    /**
     * 保存盘点任务
     */
    @ApiOperation(value = "保存盘点任务", notes = "保存盘点任务")
    @PostMapping("/planSave")
    public Result<TakeStockPlanExecuteMaterialVO> planSave(@RequestBody @Validated BaseFlowDto base) {
        return Result.OK(mobileTakeStockPlanService.planSave(base));
    }

    /**
     * 盘点小红点
     */
    @ApiOperation(value = "盘点小红点", notes = "盘点小红点")
    @GetMapping("/getRedNum")
    public Result<String> getRedNum(@ApiParam("仓库id") String warehouseId) {
        return Result.OK(mobileTakeStockPlanService.getRedNum(warehouseId));
    }

    /**
     * 待盘点/已扫描 列表
     */
    @ApiOperation(value = "待盘点/已扫描 列表", notes = "待盘点/已扫描 列表")
    @GetMapping("/listTake")
    public Result<TakeStockPlanExecuteMaterialVO> listTake(@ApiParam("盘点作业id") String id,
                                                           @ApiParam("类别，1 待盘点，2 已扫描") String type) {
        return Result.OK(mobileTakeStockPlanService.listTake(id, type));
    }
}
